//axios 封装
//请求拦截器
import Vue from 'vue'
import axios from 'axios';
import VueAxios from 'vue-axios';
import Qs from 'qs';
import storage from "@/utils/storage";

Vue.use(VueAxios, axios);

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    config.headers['Accept'] = 'application/json';
    //配置header的token信息
    const ua = window.navigator.userAgent.toLowerCase();
    const token = storage.get('token');
    if(token){
        config.headers['Authorization'] = 'Bearer ' + token;
    }
    return config;
}, function (error) {
    return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    return response.data;
}, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});
// 定义基础路由
let base = '/manage';
// 大驼峰命名请求方法名称
//登录
export const Captcha = params => { return axios.get(`${base}/captcha`, params).then(res => res)};
export const UserLogin = params => { return axios.post(`${base}/login`, Qs.stringify(params)).then(res => res)};
//管理员
export const OperateList = params => { return axios.get(`${base}/operate`, params).then(res => res)};
export const OperateUpdate = params => { return axios.post(`${base}/operate/update`, Qs.stringify(params)).then(res => res)};
export const OperateDestroy = params => { return axios.post(`${base}/operate/destroy`, Qs.stringify(params)).then(res => res)};

//店铺管理
export const ShopList = params => { return axios.get(`${base}/shop`, params).then(res => res)};
export const ShopUpdate = params => { return axios.post(`${base}/shop/update`, Qs.stringify(params)).then(res => res)};
export const ShopDestroy = params => { return axios.post(`${base}/shop/destroy`, Qs.stringify(params)).then(res => res)};
export const ShopOpen = params => { return axios.post(`${base}/shop/open`, Qs.stringify(params)).then(res => res)};
export const ShopClose = params => { return axios.post(`${base}/shop/close`, Qs.stringify(params)).then(res => res)};
export const ShopAll = params => { return axios.get(`${base}/shop/all`, params).then(res => res)};

//菜品管理
export const FoodList = params => { return axios.get(`${base}/food`, params).then(res => res)};
export const FoodUpdate = params => { return axios.post(`${base}/food/update`, Qs.stringify(params)).then(res => res)};
export const FoodDestroy = params => { return axios.post(`${base}/food/destroy`, Qs.stringify(params)).then(res => res)};
export const FoodLock = params => { return axios.post(`${base}/food/lock`, Qs.stringify(params)).then(res => res)};
export const FoodUnlock = params => { return axios.post(`${base}/food/unlock`, Qs.stringify(params)).then(res => res)};



